package com.zx.idc.backend.gui.shiro;

import com.zx.idc.common.util.PasswordDigestUtil;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;


/**
 * @auth jinyuanf
 * @date 2019/4/28 11:45
 **/
@Service("customCredentialsMatcher")
@Lazy(false)
public class CustomCredentialsMatcher extends SimpleCredentialsMatcher {

    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        char[] tokenCredentials = (char[])this.getCredentials(token);
        String passwrod = new String(tokenCredentials);
        String accountCredentials = (String)this.getCredentials(info);
        return PasswordDigestUtil.verify(passwrod, accountCredentials);
    }

}
